package Homework08;
/*
扩展练习，在BankAccount的基础上，增加一个新类earnMonthlyInterest方法被调用
并且每月三次免手续费的存款或取款，在earnMonthlyInterest方法中重置交易次数
*/
public class SavingAccount extends BankAccount {
    private int count = 3;
    private double rate = 0.01;//利率

    public SavingAccount(double initialBalance) {
        super(initialBalance);
    }

    public int getCount() {
        return count;
    }

    public void setCount(int count) {
        this.count = count;
    }

    public double getRate() {
        return rate;
    }

    public void setRate(double rate) {
        this.rate = rate;
    }

    //每月3次免手续费的机会（存款/取款）

    @Override
    public void deposit(double amount) {
        if (count > 0) {
            super.deposit(amount);
        } else {
            super.deposit(amount - 1);//手续费,把1块转入银行账号
        }
        count--;
    }

    @Override
    public void withdraw(double amount) {
        if (count > 0) {
            super.withdraw(amount);
        } else {
            super.withdraw(amount + 1);//手续费,把1块转入银行账号
        }
        count--;
    }

    public void earnMonthlyInterest() {//每月初，统计上个月的利息，同时重置免手续费的次数
        super.deposit(getBalance() * rate);
        count = 3;
    }
}
